

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;

import javax.security.auth.login.LoginException;
import javax.swing.JFrame;


public class Main extends JFrame{
	
	private static final long serialVersionUID = 1L;
	private static Scanner scanner;

	public static void main(String[] args) {
		String user,pass;
		scanner = new Scanner(System.in);
		System.out.println("Nhap username ");
		user = scanner.next();
		System.out.println("Nhap pass ");
		pass = scanner.next();
		
		Registry reg;
		Session temp;
		
		try {
			reg = LocateRegistry.getRegistry(27000);
			Login stub = (Login) reg.lookup("Login");
			temp = (Session) stub.login(user, pass.toCharArray());
			if(temp == null){
				System.out.println("dang nhap ko thanh cong");
				return;
			}
			System.out.println("Khoa thi : " + temp.getCourseTitle());
			System.out.println("Bai thi : " + temp.getExamTitle());
			System.out.println("Ho ten : " + temp.getStudentName());
			System.out.println("MSTS : " + temp.getMSTS());
			temp.startExam();
			temp.answerAQuestion(temp.getQuestions().get(0).getQuestion(), temp.getQuestions().get(0).getAnswers().get(0));	
			System.out.println(temp.getQuestions().get(0).getChosenAnswerID());
			temp.answerAQuestion(temp.getQuestions().get(0).getQuestion(), temp.getQuestions().get(0).getAnswers().get(1));
			System.out.println(temp.getQuestions().get(0).getChosenAnswerID());
		} catch(java.rmi.ConnectException connectex){
			System.out.println("Server chua duoc khoi tao");
			return;
		}
		
		catch (LoginException loginex){
			System.out.println("Khong the ket noi toi server");
			return;
		}
		catch (NotBoundException ex){
			System.out.println("ket toi duoc toi server nhung dang nhap ko thanh cong");
			return;
		}
		catch (RemoteException e) {
			System.out.println(e.getMessage() + "zx11c");
			return;
		}
		
		
	}

}
